<extend name="Public:main" />
<block name="title">订单</block>
<block name="body">
<body ng-app="myApp" ng-controller="Ctrl" ng-cloak>
    <div class="nav_top flex">
        <a  href="/index.php/Home/Transaction/purchase">
            <i></i>
        </a>
        <div class="flex1">
            订单
        </div>
        <a  href="javascript:void(0)">

        </a>
    </div>
    <div style="height: 0.44rem;"></div>
    <div class="xpay_m">
        <ul>
            <a href="/index.php/Home/Transaction/unOrderList">
                <li <if condition="$src eq 1">class="active8"</if>>
                    未完成
                </li>
            </a>
            <a href="/index.php/Home/Transaction/confirmOrderList">
                <li <if condition="$src eq 2">class="active8"</if>>
                    进行中
                </li>
            </a>
            <a href="/index.php/Home/Transaction/completeOrderList">
                <li <if condition="$src eq 3">class="active8"</if>>
                    已完成
                </li>
            </a>
        </ul>
    </div>
    <div style="height: 0.1rem;"></div>
    <div class="pay_list">
        <ul>
            <li class="flex" ng-repeat="log in logs">
                <div ng-if="log.profilephoto == '' || log.profilephoto == null">
                    <img src="__PUBLIC__/vpay/images/shezhi_icon_head.png">
                </div>
                <div ng-if="log.profilephoto != ''">
                    <img ng-src="{{ log.profilephoto }}" style="width: 100%;height: 100%;border-radius: 50%">
                </div>
                <div class="flex1">
                    <label>
                        {{ log.buyer }}<button id="tips" ng-if="log.status == 2 || log.status == 3" style="display: inline-block;background-color: #00c900;color: white;" ng-click="sellBankDetail(log.id)">银行卡信息</button>
                    </label>
                    <p>
                        时间：{{ log.createtime }}
                    </p>
                </div>
                <div style="width: 0.7rem;overflow: hidden">
                    <label>{{ log.entrustnum }}</label>

                    <button ng-if="log.status == 3 && log.type == 2" style="background: grey">
                        等待确认
                    </button>
                    <button ng-if="log.status == 2 && log.type== 2" style="background: grey">
                        等待确认
                    </button>
                    <button ng-if="log.status == 2 && log.type== 1" ng-click="confirm_cashout(log.id)">
                        确认打款
                    </button>
                    <button ng-if="log.status == 3 && log.type == 1" style="background: grey;">
                        等待确认
                    </button>
                </div>
            </li>
        </ul>
    </div>
    </div>
</body>
<block name="custom_js">
    <script>
        var app = getApp('myApp', []);
        app.controller('Ctrl', function ($scope, $http) {
            // 当前页数
            $scope.p = 0;
            // 加载完毕标志
            $scope.endflg = 0;
            // 防止重复加载
            $scope.busy = false;
            // 存放数据
            $scope.logs = [];
            // 请求数据方法
            $scope.loadMore = function(){

                if($scope.endflg == 0){
                    if($scope.busy){
                        return false;
                    }
                    $scope.busy = true;
                    $http({
                        method:'POST',
                        data:{
                            "p" : $scope.p
                        },
                        headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
                        transformRequest: function(obj) {
                            var str = [];
                            for (var p in obj) {
                                str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
                            }
                            return str.join("&");
                        },
                        url: "/index.php/Home/Transaction/confirmOrderList?p="+$scope.p,
                    }).then(function successCallback(response) {
                        $scope.busy = false;
                        if(response.data.data != '' && response.data.data != null){
                            if($scope.p > 0) {
                                layer.msg("正在加载...", {time: 500});
                            }
                        } else {
                            layer.msg("已经全部加载完了...", {time:500});
                            $scope.endflg = 1;
                            return false;
                        }
                        $scope.p++;
                        if(response.data.code == -1){
                            layer.msg(response.data.msg,{time:1500})
                        }else{
                            if(response.data.data == null){
                                layer.msg(response.data.msg,{time:1500});
                            } else {
                                // 组织数据
                                for (var i in response.data.data) {
                                    $scope.logs.push(response.data.data[i]);
                                }
                            }
                        }
                    }, function errorCallback(response) {
                        errorHandle(response);
                    });
                }else{
                    layer.msg("已经全部加载完了...", {time:500});
                }
            };
            // 进页面先加载一次数据
            $scope.loadMore();

            $(window).scroll(function(){
                var scrollTop = $(this).scrollTop();
                var scrollHeight = $(document).height();
                var windowHeight = $(this).height();
                if(scrollTop + windowHeight == scrollHeight){
                    $scope.loadMore();
                }
            });

            //确认打款
            $scope.confirm_cashout=function (id) {
                layer.confirm('确认打款？', {
                    btn: ['确认','取消'] //按钮
                }, function(){
                    $http({
                        method:'POST',
                        data:{
                            id : id
                        },
                        headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
                        transformRequest: function(obj) {
                            var str = [];
                            for (var p in obj) {
                                str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
                            }
                            return str.join("&");
                        },
                        url: "/index.php/Home/Transaction/confirm_cashout"
                    }).then(function successCallback(response) {
                        if(response.data.code==0){
                            layer.msg("已确认打款！");
                            window.location.href="/index.php/Home/Transaction/confirmOrderList"
                        }else {
                            layer.msg(response.data.msg)
                        }
                    }, function errorCallback(response) {
                        errorHandle(response);
                    });
                }, function() {
                    layer.msg('已取消');
                })
            }
            //确认订单
            //completeOrderList

            //查看银行卡信息
            $scope.sellBankDetail=function (id) {
                    $http({
                        method:'POST',
                        data:{
                            id : id
                        },
                        headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
                        transformRequest: function(obj) {
                            var str = [];
                            for (var p in obj) {
                                str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
                            }
                            return str.join("&");
                        },
                        url: "/index.php/Home/Transaction/sellBankDetail"
                    }).then(function successCallback(response) {
                        if(response.data.code==0){
                            var data=response.data.data;
                            layer.tips('<div style="background-color: #0ce1c2;">' +
                                    '<div style="text-align: left"><label style="width: 100px;">uid:<label>'+data.id+'</div>'+
                                    '<div style="text-align: left"><label style="width: 100px;">姓名:<label>'+data.realname+'</div>' +
                                    '<div style="text-align: left">手机号:'+data.account+'</div>' +
                                    '<div style="text-align: left">银行名称:'+data.bankname+'</div>' +
                                    '<div style="text-align: left">银行卡号:'+data.no+'</div></div>', '#tips', {tips: [3,'#0ce1c2']});
                           /* layer.open({
                                type: 1,
                                shadeClose: true,
                                title: false, //不显示标题
                                area: ['200px', '50%'],
                                content: '<div style="background-color: #0ce1c2"><div style="text-align: left"><label style="width: 100px;">姓名:<label>'+data.realname+'</div>' +
                                '<div style="text-align: left">银行名称:'+data.bankname+'</div>' +
                                '<div style="text-align: left">银行卡号:'+data.no+'</div></div>',
                                cancel: function(){

                                }
                            });*/
                        }else {
                            layer.msg(response.data.msg)
                        }
                    }, function errorCallback(response) {
                        errorHandle(response);
                    });

            }
        });
    </script>
</block>
</block>